require 'View.Base.BaseView'

BaseTouchView = class("BaseTouchView", BaseView)

--启动事件--
function BaseTouchView:InitPanel()
    BaseTouchView.Instance = self
    self.camera = UnityEngine.Camera.main

    self.isInMove = false
    self.lastMouseDownTime = 0
    self.lastDownPos = Vector3.New()
    self.lastPressTime = 0
    self.lastClickTime = 0

    --UpdateBeat:Add(BaseTouchView.Update, self)
end

function BaseTouchView:Update()
    if ConfirmBoxViewModelInstance then return end
    if self.camera.isActiveAndEnabled == false then return end
    if Input.GetMouseButtonDown(0) then
        self.isInMove = true
        local currentTime = Time.realtimeSinceStartup
        self.lastMouseDownTime = currentTime
        self.lastDownPos = Input.mousePosition
        self:OnMouseButtonDown(self.lastDownPos)

        if currentTime - self.lastPressTime > 0.5 then
            self.lastPressTime = currentTime
            self:OnPress(self.lastDownPos)
        end
    elseif Input.GetMouseButton(0) then
        if self.isInMove == false then
            return
        end
        local mousePosition = Input.mousePosition;
        self:OnMouseMove(mousePosition)
        self.lastDownPos = mousePosition
    elseif Input.GetMouseButtonUp(0) then
        if self.isInMove == false then
            return
        end

        self.isInMove = false
        local currentTime = Time.realtimeSinceStartup
        local screenPos = Input.mousePosition

        if currentTime - self.lastMouseDownTime < 0.15 and (screenPos - self.lastDownPos):Magnitude() < 10 then
            if currentTime - self.lastClickTime > 0.5 then
                self.lastClickTime = currentTime
                self:OnClick(screenPos)
            end
        else
            self:OnMouseButtonUp(screenPos - self.lastDownPos)
        end
    end
end

function BaseTouchView:OnDestroy()
    UpdateBeat:Remove(BaseTouchView.Update, self)
    BaseView.OnDestroy(self)
end

function BaseTouchView:OnMouseButtonDown(pos)

end

function BaseTouchView:OnPress(pos)

end

function BaseTouchView:OnMouseMove(pos)

end

function BaseTouchView:OnClick(pos)

end

function BaseTouchView:OnMouseButtonUp(deltaPos)

end

